package com.gmall.rabbitmq.consumer.service;

import com.gmall.rabbitmq.config.TopicExchange_Queue_Config;
import com.rabbitmq.client.Channel;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Service;

@Service

public class TopicExQueueService {

    @RabbitListener(queues =
            {TopicExchange_Queue_Config.TOPIC_EX_QUEUE_1,
             TopicExchange_Queue_Config.TOPIC_EX_QUEUE_2})
    public void consumeSmsMsg(Channel channal, Message message, String msg){
        try {
            long deliveryTag = message.getMessageProperties().getDeliveryTag();
            String consumerQueue =
                    message.getMessageProperties().getConsumerQueue();
            System.out.println(consumerQueue +":" +msg);

            channal.basicAck(deliveryTag,false);
            System.out.println("手动发送ACK");
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }
}
